/**
 * Update the propert in context data (stored with the element)
 * from the element.
 * 
 * @param element Element
 * @param property string
 */
function update(element, property) {
  var value = element.value;
  var path = [];
  var ok = parsePath(property, path);
      
  console.log("new value: " + value);
      
  var node = element;
  while (node && !node.__jstcontext) {
    node = node.parentNode;
  }
  if (!node) {
    console.log("Update problem: __jstcontext not found");
    return;
  }

  console.log(node.__jstcontext);

  var env = node.__jstcontext.getVariable(path[0]);
  for (var i = 1; i < path.length - 1; i++) {
    env = env[path[i]];
  }
      
  var name = path[path.length -1];
  env[name] = value;
      
  var toSend = {
    "id": env["id"], 
    "type": env["type"]
  };
  toSend[name] = {
    "connect": "update", 
    "value": env[name], 
    "lang":"/lang/en"
  };
      
  console.log("toSend:");
  console.log(toSend);
      
  mqlWrite(toSend, function(res) {
    console.log("mql write server response:");
    console.log(res);
  });
      
  // HACK
  jstProcess(node.__jstcontext, element.parentNode.parentNode);
  
  // console.log("data: " + context.data_);
}
